char *str = "Hello world!\n";

void print()
{
	asm("mov $13, %%edx \n\t"	/* edx = length 13 */
		"mov %0, %%ecx \n\t"	/* ecx = str */
		"mov $0, %%ebx \n\t"	/* ebx = 0:stdout */
		"mov $4, %%eax \n\t"	/* eax = write 系统调用号为 4 */
		"int $0x80 \n\t"		/* write(0, str, 13) */
		:: "r"(str):"edx", "ecx", "ebx");
}

void exit()
{
	asm("mov $42, %ebx \n\t"	/* ebx = 42, exit code */
		"mov $1, %eax \n\t"		/* eax = exit 系统调用号为 1 */ 
		"int $0x80 \n\t");		/* exit(42) */
}

void nomain()
{
	print();
	exit();
}

#if 0

// 使用普通命令行的方式来编译和链接:
	gcc -c -fno-builtin nomain-32bit.c
	ld -static -e nomain-32bit -o nomain-32bit nomain-32bit.o

// readelf -h nomain
ELF Header:
  Magic:   7f 45 4c 46 01 01 01 00 00 00 00 00 00 00 00 00 
  Class:                             ELF32
  Data:                              2's complement, little endian
  Version:                           1 (current)
  OS/ABI:                            UNIX - System V
  ABI Version:                       0
  Type:                              EXEC (Executable file)
  Machine:                           Intel 80386
  Version:                           0x1
  Entry point address:               0x8048094

// write 
	int write(int filedesc, char *buffer, int size);

// objdump -S nomain
nomain-32bit:     file format elf32-i386

Disassembly of section .text:

08048094 <print>:
 8048094:       55                      push   %ebp
 8048095:       89 e5                   mov    %esp,%ebp
 8048097:       53                      push   %ebx
 8048098:       a1 00 a0 04 08          mov    0x804a000,%eax
 804809d:       ba 0d 00 00 00          mov    $0xd,%edx
 80480a2:       89 c1                   mov    %eax,%ecx
 80480a4:       bb 00 00 00 00          mov    $0x0,%ebx
 80480a9:       b8 04 00 00 00          mov    $0x4,%eax
 80480ae:       cd 80                   int    $0x80
 80480b0:       5b                      pop    %ebx
 80480b1:       5d                      pop    %ebp
 80480b2:       c3                      ret    

080480b3 <exit>:
 80480b3:       55                      push   %ebp
 80480b4:       89 e5                   mov    %esp,%ebp
 80480b6:       bb 2a 00 00 00          mov    $0x2a,%ebx
 80480bb:       b8 01 00 00 00          mov    $0x1,%eax
 80480c0:       cd 80                   int    $0x80
 80480c2:       5d                      pop    %ebp
 80480c3:       c3                      ret    

080480c4 <nomain>:
 80480c4:       55                      push   %ebp
 80480c5:       89 e5                   mov    %esp,%ebp
 80480c7:       e8 c8 ff ff ff          call   8048094 <print>
 80480cc:       e8 e2 ff ff ff          call   80480b3 <exit>
 80480d1:       5d                      pop    %ebp
 80480d2:       c3                      ret    

#endif